//这是第二次测试


fn main(){
    test_basic();
}

fn what_century(year: &str) -> String {
    let mut pre:i32 = year[0..2].parse().unwrap();
    println!("pre = {}",pre);
    let lst:i32 = year[2..].parse().unwrap();
    if lst > 0 { pre += 1 };
    pre.to_string() + &(|n: i32| -> String{
        if n >= 20 {
            match n%10 {
                1 => "st".to_string(),
                2 => "nd".to_string(),
                3 => "rd".to_string(),
                _ => "th".to_string(),
            }
        }else if n >= 10 && n < 20 {
            "th".to_string()
        }else{
            String::from("th")
        }
    }(pre))
    // pre.to_string() + &(match pre%10 {
    //     1 => String::from("st"),
    //     2 => String::from("nd"),
    //     3 => String::from("rd"),
    //     _ => String::from("th"),
    // })
}

fn test_basic() {
    assert_eq!(what_century("1999"), "20th");
    assert_eq!(what_century("2011"), "21st");
    assert_eq!(what_century("2154"), "22nd");
    assert_eq!(what_century("2259"), "23rd");
    assert_eq!(what_century("1234"), "13th");
    assert_eq!(what_century("1023"), "11th");
    assert_eq!(what_century("2000"), "20th");
    assert_eq!(what_century("3210"), "33rd");        
}
